Repository navigation
Fix CI (Python + MATLAB) and three small bugs in stats - #379
Merged
Merged
Conversation
CI:
- python_unittests: bump checkout to v4 and setup-python to v5; install
setuptools/wheel explicitly before and after the editable install so
abagen's `pkg_resources` import does not break test collection on
Python 3.12 (where setuptools is no longer in the venv by default).
- MATLAB_unittests: bump checkout to v4, setup-python to v5,
setup-matlab to v2 and switch to run-command v2 so we can call
pyenv() before runtests; without it test_precomputed/load_pkl errors
with MATLAB:Python:PythonUnavailable on the GitHub runners. Drop the
unsupported R019b matrix entry (setup-matlab v2 requires R2020a+);
test against R2022a (Python 3.9) and latest (Python 3.10) instead.
Bugs:
- SLM.py: import sqrt from math, not cmath (cmath returns complex
values; the code uses real sqrt only).
- SLM.py: drop the duplicate fetch_template_surface import — it is
re-exported from brainstat.datasets and was being imported twice.
- _t_test.py: replace sys.exit("Contrast is not estimable") with
raise ValueError. Library code should never terminate the host
process; remove the now-unused `import sys`.
Two follow-ups after first CI run on this branch:
- Python jobs were still failing with ModuleNotFoundError: pkg_resources.
setuptools 82.0.1 was being installed, but setuptools 81+ no longer
exposes the legacy pkg_resources module on import. abagen 0.1.3
(resolved from `abagen>=0.1` in requirements.txt) still does
`from pkg_resources import resource_filename` at import time, so test
collection of brainstat/tests/test_genetics.py blows up. Pin
setuptools<81 in CI; force-reinstall after the editable install in
case it gets bumped back. Real fix is upstream — when abagen drops
pkg_resources, this pin can go.
- MATLAB jobs were failing with `Undefined function fetch_template_surface`
(and friends): switching from run-tests@v2 to run-command@v2 lost the
implicit `addpath(source-folder)` that run-tests does. Add an
explicit `addpath(genpath('brainstat_matlab'))` before runtests.
After the previous CI fix, jobs on Python 3.11/3.12 surface two more upstream-version regressions: - _t_test.py:175 — `float(np.sqrt(... / vf))` raises TypeError on numpy >=2.0 when the inner expression is a size-1 ndarray (numpy 2 dropped the implicit 1d→scalar conversion). Switch to `.item()`, which returns a native Python scalar in both numpy 1.x and 2.x. - abagen 0.1.3 calls `DataFrame.groupby(sid, axis=1)` in `abagen/probes_.py`, which raises in pandas 2.1+ where the `axis` keyword was removed. Until abagen ships a patched release, pin `pandas<2.1` in both setup.py install_requires and requirements.txt.
pandas<2.1 resolves to 2.0.x, whose C extensions were built against the numpy 1.x ABI. Installing it alongside numpy 2.x produces `ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject` at import time, killing test collection across every matrix entry. Pin numpy<2 so the entire stack stays on numpy 1.x ABI until abagen is patched and the pandas pin can be lifted.
pandas 2.0.x has no Python 3.12 wheels (3.12 support landed in pandas 2.1), so pip falls back to building from source — which fails because the build env doesn't have pkg_resources. With pandas pinned <2.1 (needed for the abagen groupby workaround), 3.12 simply can't be satisfied. Drop it from the matrix; add back once abagen is patched.
This was referenced May 4, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings CI back to green (Python + MATLAB suites have been red on master) and folds in three high-severity correctness fixes from a recent audit. All 9 required checks now pass on this branch.
CI
Python tests (
unittestsmatrix) — were aborting at test collection withModuleNotFoundError: No module named 'pkg_resources'. Investigation produced a chain of issues:pkg_resources. abagen 0.1.3 still importspkg_resources.setuptools<81exposed a numpy 2.x regression:float(size_1_array)raisesTypeError: only 0-dimensional arrays can be converted to Python scalars.DataFrame.groupby(sid, axis=1)which pandas 2.1 removed.pandas<2.1resolves to pandas 2.0.x whose C extensions were built against numpy 1.x ABI →numpy.dtype size changedat import.Fixes:
actions/checkout@v4andactions/setup-python@v5.setuptools<81(with re-install after the editable install in case it gets bumped back).numpy<2,>=1.21andpandas<2.1,>=1.3in bothsetup.pyandrequirements.txtso the entire stack stays on numpy-1.x ABI until abagen dropspkg_resources/groupby(axis=).float(np.sqrt(... / vf))with.item()in_t_test.py:175— works on numpy 1.x and 2.x.pandas<2.1pin); added a comment so it can be re-added once abagen is patched.MATLAB tests (
matlab_unit_testmatrix) — everytest_precomputed/*errored withMATLAB:Python:PythonUnavailablebecause the workflow installed Python 3.8 but never told MATLAB about it viapyenv. Plusmatlab-actions/setup-matlab@v0is end-of-life.matlab-actions/setup-matlab@v2andmatlab-actions/run-command@v2;pyenv('Version', ...)is now called beforeruntests.run-commandlost the implicitaddpathfromrun-tests, so addedaddpath(genpath('brainstat_matlab'))explicitly.R2022a↔3.9,latest↔3.10. Dropped the unsupportedR019bmatrix entry (setup-matlab v2 needs R2020a+).Bugs
brainstat/stats/SLM.py—from cmath import sqrtwas importing the complex square root. Switched tomath.sqrt.brainstat/stats/SLM.py—fetch_template_surfacewas being imported twice; kept the higher-level one.brainstat/stats/_t_test.py—sys.exit(...)would kill the host process when contrast is non-estimable. Replaced withraise ValueError(...).Test plan
python -m pytest brainstat/tests/test_t_test.py— 16/16 pass locally.pkg_resourcesand thegroupby(axis=)call.Follow-ups (not in this PR)
pkg_resourcesandgroupby(axis=)removals so the pins here can come off.mypyjob after [REF] Remove #type: ignore from SLM class #199 unblocks.